package protocol;

//import java.io.ByteArrayInputStream;
//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.io.ObjectInputStream;
//import java.io.ObjectOutputStream;
//import java.io.Serializable;
import java.io.*;
import java.net.InetAddress;

/**
 * @author coralie
 *
 */
public class Message implements Serializable {


	private static final long serialVersionUID = 123L;
	private String username;
	private InetAddress addressSource;
	

	public Message(String username, InetAddress addressSource){
		this.username = username;
		this.addressSource = addressSource;
	}
	
	/**
	 * Permet de Sérialiser un objet de type Message
	 * @return un tableau de byte
	 */
	/*public byte[] serialiser(){
		 byte[] result=null;
		 
		 try {

			    ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
			 	ObjectOutputStream oos= new ObjectOutputStream(bos);
				// serialisation : ecriture de l'objet dans le flux de sortie
				oos.writeObject(this); 
				// on vide le tampon
				oos.flush();
				System.out.println(this.toString() + " a ete serialise");
				result = bos.toByteArray();
			} 
		 catch(IOException ioe) {
				ioe.printStackTrace();
				System.out.println("PROBLEME methode write:" +this + "n'a pas ete serialise");
			}
		return result;
	}*/
	
	/**
	 * 
	 * @param messToRead le message � d�s�rializer
	 * @return 
	 * @return un objet de type Message
	 */
	/*public static Message deserialiser(byte[] messToRead){
		Message result = null;
		
		try {
			ByteArrayInputStream bis = new ByteArrayInputStream(messToRead);
			ObjectInputStream ois = new ObjectInputStream(bis);
			result = (Message) ois.readObject();
			
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Objet non d�s�rialis�");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Objet non d�s�rialis�");
		}
		
		return result;
		
	}*/
	
	public String getUsername(){
		return username;
	}
	
	public InetAddress getSourceAddress(){
		return addressSource;
	}
	
	public String toString(){
		return ("MESSAGE Source: "+username +";");
	}
	
}
